#!/usr/bin/env python3
# -*- encoding: utf-8 -*-
'''
@author: yuejl
@application:
@contact: lewyuejian@163.com
@file: single_mode.py
@time: 2021/10/24 0024 13:52
@desc: 单体模式
'''
from typing import Dict

#! TODO 接口自动化 请求单体模式
def execute_single_mode(test_case):
    returned_data = {}
    returned_data["id"] = test_case.get("id")
    # 测试结论
    returned_data["testConclusion"] = []
    returned_data["status"] = 'ok'
    if not isinstance(test_case, Dict):
        returned_data["status"] = 'failed'
        returned_data["testConclusion"].append('测试用例结构不正确！ ')
        return returned_data

    def validate_test_case(test_case):
        # 必需
        compulsory_key_list = ['requestProtocol', 'route', 'requestMethod']
        # 判断元素除了0、空、none、false外都为true
        return all([compulsory_key in test_case.keys() for compulsory_key in compulsory_key_list])

    if not validate_test_case(test_case):
        returned_data["status"] = 'failed'
        returned_data['testConclusion'].append('测试用例缺失必需参数！ ')
        return returned_data
    #
    # if test_case.get('isClearCookie'):
    #     self.session.cookies.clear()
